package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetMessageListBean;
import com.ymatou.iapi.csim.parameter.GetUserMessageListResp;
import com.ymatou.iapi.csim.parameter.LoginBean;
import com.ymatou.iapi.csim.parameter.OnlineBean;
import com.ymatou.iapi.csim.parameter.OpenSessionBean;
import com.ymatou.iapi.csim.parameter.SubmitSessionScoreBean;
import com.ymatou.iapi.csim.service.GetMessageListCall;
import com.ymatou.iapi.csim.service.OpenSessionCall;
import com.ymatou.iapi.csim.service.SubmitSessionScoreCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*用户提交评分
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SubmitSessionScore{
	private static SubmitSessionScoreBean bean;
	private static SubmitSessionScoreCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private Integer csId_seller=Integer.parseInt(EnvSetup.getData("csId_seller").toString());
	private Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private Integer sellerId1=Integer.parseInt(EnvSetup.getData("autotest_seller1").toString());
	private static ymt_cssessionWapper csSessionWapper=new ymt_cssessionWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户提交评分");
	}

	@Before
	public void caseUp() {
		bean=new SubmitSessionScoreBean();
		call=new SubmitSessionScoreCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SubmitSessionScore_1() {
		Logger.start(true,"用户提交评分-买家评分");
		try {
			//查询是否有在线客服 1，2
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession csSession=service.getOpenSession(csId,userId);
    		GetMessageListBean messageListBean=service.GetMessageListBean();
    		messageListBean.setSessionNumber(csSession.getSessionNumber());
    	//	messageListBean.setFromuserId(customerId);
    		messageListBean.setToUserId(userId);
    		GetMessageListCall getMessgeListcall=service.GetMessageListCall(messageListBean);
    		GetUserMessageListResp resp=getMessgeListcall.getData();
    		
    		bean.setMessageId(resp.getYmtMessageList().get(0).getMessageId());
    		bean.setSessionNumber(csSession.getSessionNumber());
    		bean.setUserId(userId);
    		bean.setScore(5);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("",call.getMsg().toString(), "验证返回的Msg");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库ymt_cssession
			ymt_cssession cssession=csSessionWapper.selectBy(MapUtil.hashMap("CSId",csId,"UserId",userId,"Status",0));
			Logger.verifyEquals(bean.getScore(), cssession.getScore(), "验证数据库Score与传入提交的一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SubmitSessionScore_2() {
		Logger.start(true,"用户提交评分-买手评分");
		try {
	    int csId=csId_seller;
	    int userId=sellerId1;
	
		  //查询是否有在线客服 1，2
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession csSession=service.getOpenSession(csId,userId);
		
    		GetMessageListBean messageListBean=service.GetMessageListBean();
    		messageListBean.setSessionNumber(csSession.getSessionNumber());
    		messageListBean.setToUserId(userId);
    		GetMessageListCall getMessgeListcall=service.GetMessageListCall(messageListBean);
    		GetUserMessageListResp resp=getMessgeListcall.getData();
    		
    		bean.setMessageId(resp.getYmtMessageList().get(0).getMessageId());
    		bean.setSessionNumber(csSession.getSessionNumber());
    		bean.setUserId(sellerId1);
    		bean.setScore(5);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("",call.getMsg().toString(), "验证返回的Msg");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库ymt_cssession
			ymt_cssession cssession=csSessionWapper.selectBy(MapUtil.hashMap("CSId",csId,"UserId",userId,"Status",0));
			Logger.verifyEquals(bean.getScore(), cssession.getScore(), "验证数据库Score与传入提交的一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}